/**
 * 
 */
package fr.gfi.agraf.vue.action.administrer.profil;

import org.apache.log4j.Logger;

import fr.gfi.agraf.exception.AgrafException;
import fr.gfi.agraf.service.IProfilService;
import fr.gfi.agraf.utils.PropertiesUtils;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.AbstractApplicationSupportAction;

/**
 * @author Zakaria
 *
 */
public class SupprimerProfilAction extends AbstractApplicationSupportAction {
	

	/**
	 * Logger
	 */
	private final static Logger LOGGER = Logger.getLogger(SupprimerProfilAction.class);

	private static final String ERREUR_ID_PROFIL_INCORRECT = "erreur.id.profil.incorrect";

	/**
	 * 
	 */
	private static final long serialVersionUID = 9120745773699651644L;

	private Long id;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.gfi.agraf.vue.action.AbstractApplicationSupportAction#executeAction()
	 */
	@Override
	public String executeAction() throws Exception {
		// Spring, recupere le service profil
		final IProfilService profilService = (IProfilService) SpringFactory.getApplicationContext().getBean(
				AjouterProfilAction.PROFIL_SERVICE);
		try {
			// fait appel au service profil
			profilService.supprimerProfil(id);
		} catch (final AgrafException ae) {
			// Recupére le message d'erreur
			final String messageErreur = PropertiesUtils.getProperty(ae.getKey());
			// Ajoute action error
			addActionError(messageErreur);
			LOGGER.error(messageErreur,ae);
			return ERROR;
		}
		return SUCCESS;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#validate()
	 */
	@Override
	public void validate() {
		if (id == null || id == 0) {
			addActionError(ERREUR_ID_PROFIL_INCORRECT);
			return;
		}
		super.validate();
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(final Long id) {
		this.id = id;
	}

}
